//
//  MovieTableViewCell.m
//  豆瓣
//
//  Created by Roach on 16/6/23.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

#define kWidth self.contentView.frame.size.width
#define kHight self.contentView.frame.size.height

@interface MovieTableViewCell ()

@property (nonatomic, retain) UIImageView *movieImageView;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UIImageView *backImageView;
@property (nonatomic, retain) UILabel *idLabel;

@end

@implementation MovieTableViewCell

- (void)dealloc {
    
    [_backImageView release];
    [_cellModel release];
    [_movieImageView release];
    [_nameLabel release];
    [_idLabel release];
    
    [super dealloc];
    
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_backImageView];
        [_backImageView release];
  
        self.movieImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_movieImageView];
        [_movieImageView release];
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.idLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_idLabel];
        [_idLabel release];
        
    }
    
    return self;
    
}

- (void)layoutSubviews {
    

    [super layoutSubviews];
    

    // movieImageView
    self.movieImageView.frame = CGRectMake(20, 20, kWidth * 0.3, kHight - 30);
    self.movieImageView.backgroundColor = [UIColor orangeColor];
    
    // nameLabel
    self.nameLabel.frame = CGRectMake(_movieImageView.frame.size.width + 40, 50, kWidth * 0.7, kHight *0.2);
    
    self.nameLabel.font = [UIFont systemFontOfSize:20];
    
//    self.nameLabel.backgroundColor = [UIColor greenColor];
    
    // backImageView
    self.backImageView.frame =CGRectMake(10, 15, kWidth, kHight - 20);
    
    
    
}


- (void) setCellModel:(MovieModel *)cellModel {
    
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    [_backImageView setImage:[UIImage imageNamed:@"bg_eventlistcell@2x.png"]];
    
    NSURL *url = [NSURL URLWithString:cellModel.pic_url];
    
    [_movieImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"dfdf.png"]];
    
    _nameLabel.text = cellModel.movieName;
    
    _idLabel .text = cellModel.movieId;
    
    
}
@end
